package process;

import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ConnectDB
{

    private static Connection connect = null;
    private static boolean connectedToDatabase = false;

    public static Connection getConnect()
    {
        return connect;
    }

    public static boolean connect(String host, String user, String pass, String port)
    {
        try
        {
            String DATABASE_URL = "jdbc:mysql://" + host + ":" + port + "/";
            connect = (Connection) DriverManager.getConnection(DATABASE_URL, user, pass);
            return true;
        }
        catch (SQLException ex)
        {
            Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    public static void closeConnect()
    {
        if (connectedToDatabase)
        {
            try
            {
                connect.close();
            }
            catch (SQLException sqlException)
            {
            }
            finally
            {
                connectedToDatabase = false;
            }
        }
    }
}
